home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
266_01
/
conlib.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-03
|
19KB
|
599 lines
/* PLOX keyword handling modules 04-21-90 FILE: CONLIB.C
Robert L. Patton, Jr.
1713 Parkcrest Terrace
Arlington, TX 76012
*/
#define HOLD 10
#define FNLEN 15
#include <stdio.h>
#include <string.h>
#include "PLOX.H"
#include "CONLIB.H"
#include "DATLIB.H"
#include "DRAWLIB.H"
#include "PXLIB.H"
#include "WORDLIB.H"
/* Global scaling parameters */
static SCALING Xfit = {0.0,20.0,4.32},
Yfit = {0.0,25.0,2.88};
static int Xlen = 6*INCH-1, Ylen = 4*INCH-1;
/* ======= */
void Unknown (Word)
/* ======= */
char *Word;
{
char Phrase[31] = " unknown keyword: ";
strncat (Phrase,Word,12);
PauseMsg (Phrase);
}
/* ===== */
void ARcon (Sentence)
/* ===== Handles an AREA specification */
char *Sentence;
{
#define INSET INCH/2
char Word[HOLD+1];
double Xarea, Yarea, Xsize, Ysize;
static int Xa, Ya;
int Border;
#ifdef DEBUG
printf("ARcon:%s\n",Sentence);
#endif
GetWord (Sentence, Word, HOLD);
Xa = INSET; Xlen = XMAX - 2 * INSET;
Ya = INSET; Ylen = YMAX - 2 * INSET;
Border = NO;
while (Word[0] != ' ') {
if (EQUAL (Word,"at")) {
GetVal (Sentence, &Xarea);
GetVal (Sentence, &Yarea);
if (Xarea<=0 || Yarea<=0)
PauseMsg(" invalid AREA location, default used ");
else {
Xa = PIXELS (Xarea);
Ya = PIXELS (Yarea);
}
}
else if (EQUAL (Word,"size")) {
GetVal (Sentence, &Xsize);
GetVal (Sentence, &Ysize);
if (Xsize==0 || Ysize==0)
PauseMsg(" invalid AREA size, default used");
else {
Xlen = PIXELS (Xsize);
Ylen = PIXELS (Ysize);
}
}
else if (EQUAL (Word,"outline")) Border = YES;
else Unknown (Word);
GetWord (Sentence, Word, HOLD);
}
PX_Origin (Xa, Ya);
if (Border) Box (0, 0, Xlen, Ylen);
}
/*@@ CONLIB-2 */
/* ===== */
void AXcon (Sentence)
/* ===== Handles an AXIS specification */
char *Sentence;
{
#define EXACT 1
char Dir, Locus, Word[HOLD+1];
double From, To;
int Axlen, Boxes, Side, Visible, Xa, Ya;
SCALING AxFit;
#ifdef DEBUG
printf("AXcon:%s\n",Sentence);
#endif
GetWord (Sentence, Word, HOLD);
/* Set all defaults */
From = 0.0; To = 0.0; Boxes = 0;
Locus = 'L'; Dir = 'V', Side = -1;
Visible = YES;
/* Interpret the specification */
while (Word[0] != ' ') {
if (EQUAL (Word,"invisible")) Visible = NO;
else if (EQUAL (Word,"above")) {Locus='A' ;Dir='H'; Side=-1;}
else if (EQUAL (Word,"below")) {Locus='B' ;Dir='H'; Side= 1;}
else if (EQUAL (Word,"right")) {Locus='R' ;Dir='V'; Side= 1;}
else if (EQUAL (Word,"left")) {Locus='L' ;Dir='V'; Side=-1;}
else if (EQUAL (Word,"boxes")) GetInt (Sentence, &Boxes);
else if (EQUAL (Word,"from")) GetVal (Sentence, &From);
else if (EQUAL (Word,"to")) GetVal (Sentence, &To);
else Unknown (Word);
GetWord (Sentence, Word, HOLD);
}
Axlen = (Dir=='V'? Ylen: Xlen);
Xa = (Locus=='R'? Xlen: 0);
Ya = (Locus=='A'? Ylen: 0);
if (From==0.0 && To==0.0) {
PauseMsg(" axis range not given, using 0 to 100");
To = 100.0;
}
Scale (From, To, Axlen, EXACT, &Boxes, &AxFit);
if (Dir == 'H') CopyScale (&AxFit, &Xfit);
else CopyScale (&AxFit, &Yfit);
if (Visible) AxNum (Xa, Ya, Dir, Side, Axlen, &AxFit, Boxes);
}
/*@@ CONLIB-3 */
void BRcon (Sentence)
/* ===== Handles a BAR specification */
#define BRBUF 12
char *Sentence;
{
double Value; /* local storage */
double Width; /* user bar spec */
float Base;
float *Xptr, *Yptr; /* pointers to plot data */
char Word[BRBUF+1]; /* local string storage */
char Fname[FNLEN+1]; /* file name for data */
char Dtype[MAXITEMS]; /* data type for any item */
char Dir; /* bar direction (H,V) */
int Ix, Iy; /* item no. in data line */
int Foot, Thick; /* pixel bar specs */
int Rank, Of, Offset;/* abutted bar specs */
int Xfoot, Yfoot; /* local storage */
int Xbar, Ybar;
int BaseSet; /* flag for user set base */
int Points; /* no. of data points */
int Hatch, Gap; /* bar hatch pattern code */
int k; /* local storage */
#ifdef DEBUG
printf("BRcon:%s\n",Sentence);
#endif
GetWord (Sentence, Word, BRBUF);
/* set defaults */
Fname[0] = ' ';
for (k=0; k<MAXITEMS; k++) Dtype[k] = 'N';
Ix = 1; Iy = 2;
Width = .125; Dir = 'V'; BaseSet = NO;
Rank = 1; Of = 1;
Hatch = 0; Gap = 4;
/* Interpret specification */
while (Word[0]!=' ') {
if (EQUAL (Word,"file")) GetWord (Sentence, Fname, FNLEN);
else if (EQUAL (Word,"items")) SetItems (Sentence, &Ix, &Iy);
else if (EQUAL (Word,"item")) SetDtype (Sentence, Dtype);
else if (EQUAL (Word,"base")) {GetVal (Sentence, &Value);
Base = (float) Value;
BaseSet = YES; }
else if (EQUAL (Word,"width")) GetVal (Sentence, &Width);
else if (EQUAL (Word,"hor") ||
EQUAL (Word,"H") ) Dir = 'H';
else if (EQUAL (Word,"ver") ||
EQUAL (Word,"V") ) Dir = 'V';
else if (EQUAL (Word,"hatch")) {
GetWord (Sentence, Word, BRBUF);
if (EQUAL (Word,"H") ||
EQUAL (Word,"hor")) Hatch = 1;
else if (EQUAL (Word,"V") ||
EQUAL (Word,"ver")) Hatch = 2;
else if (EQUAL (Word,"right")) Hatch = 3;
else if (EQUAL (Word,"left")) Hatch = 4;
else if (EQUAL (Word,"square")) Hatch = 5;
else if (EQUAL (Word,"blank")) Hatch = 6;
else Unknown (Word);
}
else if (EQUAL (Word,"gap")) {
GetInt (Sentence, &Gap);
if (Gap <= 0) {
PauseMsg (" positive number must follow 'gap'");
Gap = 4;
}
}
/*@@ CONLIB-4 */
else if (EQUAL (Word,"abut")) {
GetInt (Sentence, &Rank);
GetInt (Sentence, &Of);
if (Rank > Of || Rank <= 0) {
PauseMsg (" error in abut specification");
Rank = 1; Of = 1;
}
}
else Unknown (Word);
GetWord (Sentence, Word, BRBUF);
}
/* Draw bars */
if (Fname[0]==' ')
PauseMsg(" no data file given - no bars drawn");
else {
GetTwo (Fname, &Xptr, Dtype[Ix-1], Ix, &Yptr, Dtype[Iy-1], Iy);
Points = (int) *Xptr;
if (Points == 0) {printf(" no data found for: "); PauseMsg(Fname);}
else {
PX_Style (Hatch, Gap);
Thick = PIXELS (Width);
Offset = (Thick * ((Rank<<1) - Of - 1)) / 2;
if (BaseSet) Foot = Scaled (&Base, Dir=='V'? &Yfit: &Xfit);
else Foot = 0;
printf(" drawing %d bars\n",Points);
for (k=1; k<=Points; k++) {
Xbar = Scaled (++Xptr, &Xfit);
Ybar = Scaled (++Yptr, &Yfit);
if (Dir == 'V') {Xbar += Offset; Xfoot = Xbar; Yfoot = Foot;}
else {Ybar += Offset; Xfoot = Foot; Yfoot = Ybar;}
Bar (Xfoot, Yfoot, Xbar, Ybar, Dir, Thick, Hatch, Gap);
}
}
}
}
/*@@ CONLIB-5 */
void IScon (Sentence)
/* ===== Handles an ISO (gram) specification */
#define ISBUF 12
char *Sentence;
{
float Xdata[3]; /* isogram line x points */
float Ydata[3]; /* isogram line y points */
char Vword[ISBUF+1]; /* local string storag